package com.jiegui.socket;

import cn.hutool.core.date.DateUtil;
import com.jiegui.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.Socket;
import java.util.Arrays;
import java.util.Date;
import java.util.Random;

/**
 * @description: socket消息解析
 * @author: wuqicheng
 * @time: 16/2/2023 下午 2:32
 */
public class SocketSendUtil {
    private static final Logger logger = LoggerFactory.getLogger("file-socket");


    public static void sendMsg(String[] cmd, String ip) {
        try {

            String[] split = cmd;
            byte[] bs = new byte[split.length];
            for (int i = 0; i < split.length; i++) {
                bs[i] = (byte) Integer.parseInt(split[i], 16);
            }
            Socket socket1 = DelongServerSocket.clientsMap.get(ip).getSocket();
            socket1.getOutputStream().write(bs);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("消息发送失败接收Ip为{}，消息体为{}", ip, cmd);
        } finally {
            logger.info("发送IP为{}，发送的消息为：{}", ip, cmd);
        }
    }
}
